unit unEventos;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, Grids, DBGrids, ThemeDBGrid, DB, StdCtrls, Buttons, ComCtrls;

type
 TfmEventos = class(TForm)
  btResultados: TBitBtn;
  btFechar: TBitBtn;
  PageControl1: TPageControl;
  TabSheet1: TTabSheet;
  ThemeDBGrid1: TThemeDBGrid;
  dsEventos: TDataSource;
  procedure btFecharClick(Sender: TObject);
  procedure FormCreate(Sender: TObject);
  procedure FormClose(Sender: TObject; var Action: TCloseAction);
  procedure btResultadosClick(Sender: TObject);
  procedure FormKeyPress(Sender: TObject; var Key: Char);
  procedure ThemeDBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
   DataCol: Integer; Column: TColumn; State: TGridDrawState);
 private
    { Private declarations }
 public
    { Public declarations }
 end;
 
var
 fmEventos: TfmEventos;
 
implementation

uses unDM, unResultados, unGrafico;

{$R *.dfm}

procedure TfmEventos.btFecharClick(Sender: TObject);
begin
 Close
end;

procedure TfmEventos.btResultadosClick(Sender: TObject);
begin
 fmResultados := TfmResultados.Create(Self);
 dm.tabEventos.Edit;
 fmResultados.TabSheet1.Caption := dm.tabEventosEvento.Value;
 fmResultados.ShowModal;
 fmResultados.Free;
end;

procedure TfmEventos.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 dm.tabEventos.Close;
end;

procedure TfmEventos.FormCreate(Sender: TObject);
begin
 dm.tabEventos.Close;
 dm.tabEventos.SQL.Clear;
 dm.tabEventos.SQL.Text := 'SELECT * FROM eventos ORDER BY idevento';
 dm.tabEventos.Open;
end;

procedure TfmEventos.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key = #27 then
  Close;
end;

procedure TfmEventos.ThemeDBGrid1DrawColumnCell(Sender: TObject;
 const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
 if dm.tabEventosFinalizada.Value = True then
  if ThemeDBGrid1.Canvas.Brush.Color = ThemeDBGrid1.Color then
   ThemeDBGrid1.Canvas.Brush.Color := clMoneyGreen;
 
 ThemeDBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

end.

